import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		
	},
	mutations: {
		SET_SHIPMENT_DATA: (state, shipmentData) => {
			state.shipmentData = shipmentData
		},
		
	},
	actions: {
		// 合并
		combine({
			commit,
			state
		}) {
			return new Promise((resolve) => {
				let List = state.damagedPhotos.concat(state.tagPhotos_CTN_NO, state.tagPhotos_TRAY_NO,state.otherPhotos);
				let imageList = List.map((item, index) => {
					return {
						sequence: index,
						imageName: item.imageName,
						imageType: item.imageType
					}
				})
				let result = {
					userId: uni.getStorageSync('userinfo').userId,
					shipmentId: state.shipmentData.shipmentId,
					imageList
				};

				Object.assign(result, state.damagedInfo)
				console.log({result})
				resolve(result)
			})
		},
		// 重置
		reset({
			commit,
			state
		}) {
			return new Promise((resolve) => {
				commit('SET_SHIPMENT_DATA', {
					shipmentId: '',
					partNo: '',
					supplierName: '',
					qty: '',
					eta: '',
					hawb: '',
					asn: ''
				})
				commit('SET_DAMAGED_INFO', {
					model: '',
					cartonNo: '',
					qty: '',
					damageLevel: '',
					damageType: ''
				})
				commit('SET_DAMAGED_PHOTOS', [])
				commit('SET_TAG_PHOTOS_CTN_NO', [])
				// commit('SET_TAG_PHOTOS_TRAY_NO', [])
				commit('SET_OTHER_PHOTOS', [])
				resolve()
			})
		},
		// 重置 除shipmentid
		nextBox({
			commit,
			state
		}) {
			return new Promise((resolve) => {
				commit('SET_DAMAGED_INFO', {
					model: '',
					cartonNo: '',
					qty: '',
					damageLevel: '',
					damageType: ''
				})
				commit('SET_DAMAGED_PHOTOS', [])
				commit('SET_TAG_PHOTOS_CTN_NO', [])
				// commit('SET_TAG_PHOTOS_TRAY_NO', [])
				commit('SET_OTHER_PHOTOS', [])
				resolve()
			})
		}
	}
})
export default store
